package com.mall.shopping.services;

import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.ProductCateDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class ProductCateServiceImpl implements IProductCateService {
    @Autowired
    ItemCatMapper itemCatMapper;
    @Autowired
    ProductCateConverter productCateConverter;

    @Override
    public AllProductCateResponse getAllProductCate(AllProductCateRequest request) {

        Example example = new Example(ItemCat.class);
        example.orderBy(request.getSort()).asc();
        List<ItemCat> itemCats = itemCatMapper.selectByExample(example);
        List<ProductCateDto> productCateDtos = productCateConverter.items2Dto(itemCats);

        AllProductCateResponse allProductCateResponse = new AllProductCateResponse();
        allProductCateResponse.setProductCateDtoList(productCateDtos);
        return allProductCateResponse;
    }
}
